package cn.beforedark.yygh.hosp.controller.admin;


import cn.beforedark.yygh.common.result.R;
import cn.beforedark.yygh.dto.hosp.HospitalQueryDto;
import cn.beforedark.yygh.hosp.service.HospitalService;
import cn.beforedark.yygh.model.hosp.Hospital;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/hosp/hospital")
// @CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;


    /**
     * 分页获取医院信息
     *
     * @param pageNum  pageNum
     * @param pageSize pageSize
     * @param dto      dto
     * @return vo
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public R getHospitalPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             HospitalQueryDto dto) {
        Page<Hospital> page = hospitalService.getHosptialPage(pageNum, pageSize, dto);

        return R.ok().data("total", page.getTotalElements()).data("list", page.getContent());
    }

    /**
     * 修改医院上线状态：
     *
     * @param id     医院id
     * @param status ( 0:未上线 ) ( 1:已上线 )
     * @return vo
     */
    @GetMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id") String id,
                          @PathVariable("status") Integer status) {

        hospitalService.updateStatus(id, status);
        return R.ok();
    }

    /**
     * 根据医院id获得医院详情
     *
     * @param id 医院id
     * @return vo
     */
    @GetMapping("/detail/{id}")
    public R detail(@PathVariable("id") String id) {
        Hospital hospital = hospitalService.getDetailById(id);
        return R.ok().data("hospital", hospital);
    }

}
